package test.redis.tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class RedisToolConfig {
    
    public static String host;
    public static String auth;
    public static String masterName;
    public static int maxTotal;
    public static int maxWaitMillis;
    public static int maxIdle;
    public static int minIdle;
    public static int database;

    public static void loadConfig() {
        String confPath = Utils.getConfPath();
        Properties prop = new Properties();
        try {
            InputStream input = new FileInputStream(new File(confPath));
            prop.load(input);
            host = prop.getProperty(RedisConst.Config.URL);
            auth = prop.getProperty(RedisConst.Config.AUTH);
            masterName = prop.getProperty(RedisConst.Config.MASTER_NAME);
            database = Integer.valueOf(prop.getProperty(RedisConst.Config.DATABASE));
            minIdle = Integer.valueOf(prop.getProperty(RedisConst.Config.MIN_IDLE));
            maxIdle = Integer.valueOf(prop.getProperty(RedisConst.Config.MAX_IDLE));
            maxWaitMillis = Integer.valueOf(prop.getProperty(RedisConst.Config.MAX_WAIT_MILLS));
            maxTotal = Integer.valueOf(prop.getProperty(RedisConst.Config.MAX_TOTAL));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
